﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebUI.Areas.Bots.Models;

namespace WebUI.Areas.Bots.Binders
{
    public class NotificationSettingBinder : IModelBinder
    {
        private const string sessionKey = "NotificationSetting";

        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var notificationSetting = (NotificationSetting)controllerContext.HttpContext.Session[sessionKey];
            
            if (notificationSetting == null)
            {
                notificationSetting = new NotificationSetting();
                controllerContext.HttpContext.Session[sessionKey] = notificationSetting;
            }

            return notificationSetting;
        }
    }
}